A thread is a complete program. That is, a thread contains all the information of variables, function calls, and executing commands. Two threads cannot "talk" to each other, because each is a totally encapsulated program. However, they are powerful because since they can run concurrently, you can increase preformance, and give the user a better interface. For example, while you are waiting for user input, you could be doing other miscellaneous tasks. To illustrate threads, consider the following program which finds the minimum and maximum value of a list and prints the results:
def min(list)
{
x = 9999;
for(k in list)
if (k < x) x = k;
return x;
}
def max(list)
{
x = -9999;
for(k in list)
if (k > x) x = k;
return x;
}
def PrintMin(list) { println("The min of ",list," is ",min(list)); }
def PrintMax(list) { println("The max of ",list," is ",max(list)); }
def main()
{
list = [4,2,5,3,1];
PrintMin(list);
PrintMax(list);
}